<script setup lang="ts">
import { useMemberStore } from '@/stores';

// 获取屏幕边界到安全区域距离
const { safeAreaInsets } = uni.getSystemInfoSync()
// 订单选项
const orderTypes = [
  { type: 1, text: '待付款', icon: 'icon-daifukuan1' },
  { type: 2, text: '待发货', icon: 'icon-daifahuo1' },
  { type: 3, text: '待收货', icon: 'icon-daishouhuo1' },
  { type: 4, text: '待评价', icon: 'icon-31daipingjia' },
]

// 功能选项
const abilityTypes = [
  { type: 1, text: '地址管理', icon: 'icon-dizhi', url:'/pagesMember/address/address' },
  { type: 2, text: '我的收藏', icon: 'icon-shoucang' , url:'/pagesMember/collect/collect' },
  { type: 3, text: '系统设置', icon: 'icon-shezhi' , url:'/pagesMember/settings/settings' },
]

// 获取会员信息
const useMember = useMemberStore()
</script>

<template>
  <view class="viewport">
    <!-- 个人资料 -->
    <view class="profile" :style="{ paddingTop: safeAreaInsets!.top + 'px' }">
      <!-- 情况1：已登录 -->
      <view class="overview" v-if="useMember.profile">
        <navigator url="/pagesMember/profile/profile" hover-class="none">
          <image
            class="avatar"
            mode="aspectFill"
            :src="useMember.profile.header"
          ></image>
        </navigator>
        <view class="meta">
          <view class="nickname"> {{ useMember.profile.username }} </view>
          <navigator class="extra" url="/pagesMember/profile/profile" hover-class="none">
            <text class="update">更新头像昵称</text>
          </navigator>
        </view>
      </view>
      <!-- 情况2：未登录 -->
      <view class="overview" v-else>
        <navigator url="/pages/login/login" hover-class="none">
          <image
            class="avatar gray"
            mode="aspectFill"
            src="http://yjy-xiaotuxian-dev.oss-cn-beijing.aliyuncs.com/picture/2021-04-06/db628d42-88a7-46e7-abb8-659448c33081.png"
          ></image>
        </navigator>
        <view class="meta">
          <navigator url="/pages/login/login" hover-class="none" class="nickname">
            未登录
          </navigator>
          <view class="extra">
            <text class="tips">点击登录账号</text>
          </view>
        </view>
      </view>
      <navigator class="settings" url="/pagesMember/settings/settings" hover-class="none">
        设置
      </navigator>
    </view>
    <!-- 我的订单 -->
    <view class="orders">
      <view class="title">
        我的订单
        <navigator class="navigator" url="/pagesOrder/list/list?type=-1" hover-class="none">
          全部<text class="icon-youjiantou1"></text>
        </navigator>
      </view>
      <view class="section">
        <!-- 订单 -->
        <navigator
          v-for="item in orderTypes"
          :key="item.type"
          :class="item.icon"
          :url="`/pagesOrder/list/list?type=${item.type}`"
          class="navigator"
          hover-class="none"
        >
          {{ item.text }}
        </navigator>
        <!-- 客服 -->
        <!-- <button class="contact icon-handset" open-type="contact">售后</button> -->
      </view>
    </view>

    <view class="ability">
      <navigator v-for="item in abilityTypes" class="ability-item" :url="item.url" :key="item.type" hover-class="none">
        <text :class="item.icon" class="item-icon"></text>
        <view class="item-title" :style="[item.type === abilityTypes.length? 'border:none':''] ">
          {{ item.text }}
          <text class="icon-youjiantou1"></text>
        </view>
      </navigator>
    </view>
  </view>
</template>

<style lang="scss">
page {
  height: 100%;
  overflow: hidden;
  background-color: rgb(244, 245, 247);
}

.viewport {
  height: 100%;
}

/* 用户信息 */
.profile {
  position: relative;
  background: #E44D26;  /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #F16529, #E44D26);  /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #F16529, #E44D26); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */

  padding-bottom: 30rpx;
  .overview {
    display: flex;
    height: 120rpx;
    padding: 0 36rpx;
    color: #fff;
  }

  .avatar {
    width: 120rpx;
    height: 120rpx;
    border-radius: 50%;
    background-color: #eee;
  }

  .gray {
    filter: grayscale(100%);
  }

  .meta {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
    line-height: 30rpx;
    padding: 16rpx 0;
    margin-left: 20rpx;
  }

  .nickname {
    max-width: 350rpx;
    margin-bottom: 16rpx;
    font-size: 32rpx;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .extra {
    display: flex;
    font-size: 20rpx;
  }

  .tips {
    font-size: 25rpx;
  }

  .update {
    padding: 3rpx 10rpx 1rpx;
    color: rgba(255, 255, 255, 0.8);
    border: 1rpx solid rgba(255, 255, 255, 0.8);
    margin-right: 10rpx;
    border-radius: 30rpx;
  }

  .settings {
    position: absolute;
    bottom: 12rpx;
    right: 40rpx;
    font-size: 30rpx;
    color: #fff;
  }
}

/* 我的订单 */
.orders {
  position: relative;
  z-index: 99;
  padding: 30rpx;
  margin: 25rpx 20rpx 0;
  background-color: #fff;
  border-radius: 10rpx;
  box-shadow: 0 4rpx 6rpx rgba(240, 240, 240, 0.6);

  .title {
    height: 40rpx;
    line-height: 40rpx;
    font-size: 28rpx;
    color: #1e1e1e;

    .navigator {
      font-size: 24rpx;
      color: #939393;
      float: right;
    }
  }

  .section {
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 40rpx 20rpx 10rpx;
    .navigator,
    .contact {
      text-align: center;
      font-size: 24rpx;
      color: #333;
      &::before {
        display: block;
        font-size: 60rpx;
        color: #ff9545;
      }
    }
    .contact {
      padding: 0;
      margin: 0;
      border: 0;
      background-color: transparent;
      line-height: inherit;
    }
  }
}

/* 功能模块 */
.ability {
  background-color: #fff;
  margin: 60rpx 20rpx;
  padding: 20rpx 30rpx;
  border-radius: 10rpx;
  box-shadow: 0 4rpx 6rpx rgba(240, 240, 240, 0.6);

  &-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 28rpx;
    .item-icon{
      width:40rpx;
      height: 100rpx;
      line-height: 100rpx;
      color: #ff9545;

    }

    .item-title{
      width: 100%;
      margin-left: 8px;
      height: 100rpx;
      border-bottom: 1px solid rgba(224, 223, 223, 0.658);
      line-height: 100rpx;
      display: flex;
      justify-content: space-between;
    }
  }
}

</style>